package com.JL.engine.components;

import com.JL.engine.model.Component;
import com.JL.engine.model.View;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class ViewComponent extends Component {
    private ConcurrentLinkedQueue<View> views = new ConcurrentLinkedQueue<>();

    private int zindex = 0;

    public ConcurrentLinkedQueue<View> getViews(){
        return views;
    }

    public void setViews(ConcurrentLinkedQueue<View> views){
        this.views = views;
    }

    public int getZIndex(){
        return zindex;
    }

    public void setZIndex(int zindex){
        this.zindex = zindex;
    }

    public void addView(View view){
        views.add(view);
    }

    public void removeView(View view){
        views.remove(view);
    }


    public void draw(Graphics g){

        List<View>views = new ArrayList<>(this.views);
        Collections.sort(views, ((o1, o2) -> o1.getZIndex() - o2.getZIndex()));

        for(View view : views){
            view.draw(g, this.entity);
        }
    }

}
